package com.wyj.log

import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.flattener.Flattener
import com.elvishew.xlog.flattener.Flattener2
import java.text.SimpleDateFormat
import java.util.*


/**
 * Simply join the timestamp, log level, tag and message together.
 *
 * @since 1.3.0
 */
class DefaultFlattener : Flattener, Flattener2 {
    private val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    override fun flatten(logLevel: Int, tag: String, message: String): CharSequence {
        return flatten(System.currentTimeMillis(), logLevel, tag, message)
    }

    override fun flatten(timeMillis: Long, logLevel: Int, tag: String, message: String): CharSequence {
        return (sdf.format(Date(timeMillis))
                + '|' + LogLevel.getShortLevelName(logLevel)
                + '|' + tag
                + '|' + message)
    }
}